home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / sysdeps / unix / bsd / __tcgetatr.c < prev    next >
C/C++ Source or Header  |  1992-07-30  |  4KB  |  129 lines

  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <errno.h>
  21. #include <stddef.h>
  22. #include <termios.h>
  23.  
  24. #include "bsdtty.h"
  25.  
  26. extern CONST speed_t __bsd_speeds[]; /* Defined in tcsetattr.c.  */
  27.  
  28. /* Put the state of FD into *TERMIOS_P.  */
  29. int
  30. DEFUN(__tcgetattr, (fd, termios_p),
  31.       int fd AND struct termios *termios_p)
  32. {
  33.   struct sgttyb buf;
  34.   struct tchars tchars;
  35.   struct ltchars ltchars;
  36.   int local;
  37. #ifdef    TIOCGETX
  38.   int extra;
  39. #endif
  40.  
  41.   if (termios_p == NULL)
  42.     {
  43.       errno = EINVAL;
  44.       return -1;
  45.     }
  46.  
  47.   if (__ioctl(fd, TIOCGETP, &buf) < 0 ||
  48.       __ioctl(fd, TIOCGETC, &tchars) < 0 ||
  49.       __ioctl(fd, TIOCGLTC, <chars) < 0 ||
  50. #ifdef    TIOCGETX
  51.       __ioctl(fd, TIOCGETX, &extra) < 0 ||
  52. #endif
  53.       __ioctl(fd, TIOCLGET, &local) < 0)
  54.     return -1;
  55.  
  56.   termios_p->__ispeed = __bsd_speeds[(unsigned char) buf.sg_ispeed];
  57.   termios_p->__ospeed = __bsd_speeds[(unsigned char) buf.sg_ospeed];
  58.  
  59.   termios_p->c_iflag = 0;
  60.   termios_p->c_oflag = 0;
  61.   termios_p->c_cflag = 0;
  62.   termios_p->c_lflag = 0;
  63.   termios_p->c_oflag |= CREAD | HUPCL;
  64. #ifdef    LPASS8
  65.   if (local & LPASS8)
  66.     termios_p->c_oflag |= CS8;
  67.   else
  68. #endif
  69.     termios_p->c_oflag |= CS7;
  70.   if (!(buf.sg_flags & RAW))
  71.     {
  72.       termios_p->c_iflag |= IXON;
  73.       termios_p->c_cflag |= OPOST;
  74. #ifndef    NOISIG
  75.       termios_p->c_lflag |= ISIG;
  76. #endif
  77.     }
  78.   if ((buf.sg_flags & (CBREAK|RAW)) == 0)
  79.     termios_p->c_lflag |= ICANON;
  80.   if (!(buf.sg_flags & RAW) && !(local & LLITOUT))
  81.     termios_p->c_oflag |= OPOST;
  82.   if (buf.sg_flags & CRMOD)
  83.     termios_p->c_iflag |= ICRNL;
  84.   if (buf.sg_flags & TANDEM)
  85.     termios_p->c_iflag |= IXOFF;
  86. #ifdef    TIOCGETX
  87.   if (!(extra & NOISIG))
  88.     termios_p->c_lflag |= ISIG;
  89.   if (extra & STOPB)
  90.     termios_p->c_cflag |= CSTOPB;
  91. #endif
  92.  
  93.   switch (buf.sg_flags & (EVENP|ODDP))
  94.     {
  95.     case EVENP|ODDP:
  96.       break;
  97.     case ODDP:
  98.       termios_p->c_cflag |= PARODD;
  99.     default:
  100.       termios_p->c_cflag |= PARENB;
  101.       termios_p->c_iflag |= IGNPAR | INPCK;
  102.       break;
  103.     }
  104.   if (buf.sg_flags & ECHO)
  105.     termios_p->c_lflag |= _ECHO;
  106.   if (local & LCRTERA)
  107.     termios_p->c_lflag |= ECHOE;
  108.   if (local & LCRTKIL)
  109.     termios_p->c_lflag |= ECHOK;
  110.   if (local & LTOSTOP)
  111.     termios_p->c_lflag |= _TOSTOP;
  112.   if (local & LNOFLSH)
  113.     termios_p->c_lflag |= _NOFLSH;
  114.  
  115.   termios_p->c_cc[VEOF] = tchars.t_eofc;
  116.   termios_p->c_cc[VEOL] = '\n';
  117.   termios_p->c_cc[VERASE] = buf.sg_erase;
  118.   termios_p->c_cc[VKILL] = buf.sg_kill;
  119.   termios_p->c_cc[VINTR] = tchars.t_intrc;
  120.   termios_p->c_cc[VQUIT] = tchars.t_quitc;
  121.   termios_p->c_cc[VSTART] = tchars.t_startc;
  122.   termios_p->c_cc[VSTOP] = tchars.t_stopc;
  123.   termios_p->c_cc[VSUSP] = ltchars.t_suspc;
  124.   termios_p->c_cc[VMIN] = -1;
  125.   termios_p->c_cc[VTIME] = -1;
  126.  
  127.   return 0;
  128. }
  129.